﻿using IDAL;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAL
{
    /// <summary>
    /// 刘志超
    /// </summary>
    public class RoomIntensiveDAL : IRoomIntensiveDAL
    {

        /// <summary>
        /// 新增病房
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AddRoom(RoomIntensive m)
        {
            using (MyDBContext db = new MyDBContext())
            {
                db.RoomIntensive.Add(m);
                return db.SaveChanges();
            }

        }
        /// <summary>
        /// 病房分配
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<RoomIntensive> GetRoom()
        {
            using (MyDBContext db = new MyDBContext())
            {

                var list = db.RoomIntensive.ToList();  
                //if (!string.IsNullOrEmpty(name))
                //{
                //    list = list.Where(e => e.RoomIntensive_Number.Contains(name));
                //}
                return list;
            }

        }


        /// <summary>
        /// 病房类型下拉
        /// </summary>
        /// <returns></returns>
        public List<RoomType> GetRoomTypes()
        {
            using (MyDBContext db = new MyDBContext())
            {
                var list = db.RoomType.ToList();
                return list;
            }

        }

        /// <summary>
        /// 病房详情
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public RoomIntensive GetRoomById(int pid)
        {
            using (MyDBContext db = new MyDBContext())
            {
                return db.RoomIntensive.Where(e => e.RoomIntensive_Id == pid).FirstOrDefault();
            }
        }

        /// <summary>
        /// 编辑病房
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int UptRoom(RoomIntensive m)
        {
            using (MyDBContext db = new MyDBContext())
            {
                db.RoomIntensive.Attach(m);
                db.Entry(m).State = EntityState.Modified;
                return db.SaveChanges();
            }

        }




    }
}